<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>回顾Object.defineProperty方法</title>
  </head>
  <body>
    <script>
      let num = 18;
      let person = {
        name: "张三",
        sex: "男",
      };

      Object.defineProperty(person, "age", {
        // value: 18,
        // enumerable: true,// 控制属性是否可以被枚举,默认值false
        // writable: true,// 控制属性是否可以被修改,默认值false
        // configurable: true,// 控制属性是否可以被删除,默认值false
        get() {
          return num;
        },
        set(v) {
          num = v;
        },
      });

      // person.age = 19;
      // delete person.age;
      console.log(person);
      // console.log(Object.keys(person))
      /* for(let key in person){
          console.log(key, person[key])
      } */
    </script>
  </body>
</html>
